import { request } from '@/utils/request';
import { encryption, isEmpty } from '@/utils/utils';

export function loginByUsername (userInfo) {
    let param = encryption({
        data: userInfo,
        key: '1234567887654321',
        param: ['password'],
    });
    param.grant_type = 'password';
    param.password = param.password.replace(/\=/g, "%3D");
    let url = '/auth-v3/oauth/token?username=' + param.username + '&password=' + param.password + '&randomStr=&code=&grant_type=password&scope=server';
    url = url.replace(/\+/g, "%2B");
    return request({
        url: url,
        method: 'post',
        params: param,
        headers: {
            'Authorization': "Basic bWVzLWhvZm86bWVzLWhvZm8",
            'cataType': 'mes-hofo',
            'client-id': 'mes-hofo',
            'corp-code': 'MES-HOFO',
        }
    });
};

export function checkTicket (params) {
    return request({
        url: '/adient-pms/api/checkTicket',
        method: 'get',
        params
    })
}

export function getSiteInfo (userName) {
    return request({
        url: '/admin-v3/user/siteInfo/' + userName,
        method: 'get',
        headers: {
            'Authorization': 'Basic bWVzLWhvZm86bWVzLWhvZm8'
        }
    });
}

export const listWorkshop = () => {
    return request({
        url: '/adient-pms/pc/base/workShop/list',
        method: 'get'
    });
};